package com.ruoyi.procurementmanagement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.procurementmanagement.domain.ErpPurchasePrice;
import com.ruoyi.procurementmanagement.service.IErpPurchasePriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购价格分析Controller
 * 
 * @author ruoyi
 * @date 2025-05-12
 */
@RestController
@RequestMapping("/procurementmanagement/purchaseprice")
public class ErpPurchasePriceController extends BaseController
{
    @Autowired
    private IErpPurchasePriceService erpPurchasePriceService;

    /**
     * 查询采购价格分析列表
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:purchaseprice:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpPurchasePrice erpPurchasePrice)
    {
        startPage();
        List<ErpPurchasePrice> list = erpPurchasePriceService.selectErpPurchasePriceList(erpPurchasePrice);
        return getDataTable(list);
    }

    /**
     * 导出采购价格分析列表
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:purchaseprice:export')")
    @Log(title = "采购价格分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpPurchasePrice erpPurchasePrice)
    {
        List<ErpPurchasePrice> list = erpPurchasePriceService.selectErpPurchasePriceList(erpPurchasePrice);
        ExcelUtil<ErpPurchasePrice> util = new ExcelUtil<ErpPurchasePrice>(ErpPurchasePrice.class);
        util.exportExcel(response, list, "采购价格分析数据");
    }

    /**
     * 获取采购价格分析详细信息
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:purchaseprice:query')")
    @GetMapping(value = "/{priceid}")
    public AjaxResult getInfo(@PathVariable("priceid") Long priceid)
    {
        return success(erpPurchasePriceService.selectErpPurchasePriceByPriceid(priceid));
    }

    /**
     * 新增采购价格分析
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:purchaseprice:add')")
    @Log(title = "采购价格分析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpPurchasePrice erpPurchasePrice)
    {
        return toAjax(erpPurchasePriceService.insertErpPurchasePrice(erpPurchasePrice));
    }

    /**
     * 修改采购价格分析
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:purchaseprice:edit')")
    @Log(title = "采购价格分析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpPurchasePrice erpPurchasePrice)
    {
        return toAjax(erpPurchasePriceService.updateErpPurchasePrice(erpPurchasePrice));
    }

    /**
     * 删除采购价格分析
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:purchaseprice:remove')")
    @Log(title = "采购价格分析", businessType = BusinessType.DELETE)
	@DeleteMapping("/{priceids}")
    public AjaxResult remove(@PathVariable Long[] priceids)
    {
        return toAjax(erpPurchasePriceService.deleteErpPurchasePriceByPriceids(priceids));
    }
}
